//
//  mp3TableViewController.m
//  mp3播放器
//
//  Created by Justsoso on 16/4/5.
//  Copyright © 2016年 Justsoso. All rights reserved.
//

#import "Mp3TableViewController.h"

#import "Mp3Model.h"
#import "PlayerViewController.h"

@interface Mp3TableViewController ()

@property (nonatomic,strong) NSMutableArray *list;

@property (nonatomic,strong) NSIndexPath *curSel;

@end

@implementation Mp3TableViewController

/* 懒加载 */
- (NSMutableArray *)list
{
    if (_list == nil)
    {
        _list = [NSMutableArray array];
        NSString *path = [[NSBundle mainBundle] pathForResource:@"Musics" ofType:@"plist"];
        NSArray *arr = [NSArray arrayWithContentsOfFile:path];
        for (NSDictionary *d in arr)
        {
            Mp3Model *m = [Mp3Model mp3WithDict:d];
            [_list addObject:m];
        }
    }
    return _list;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
}


#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.list.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    
    // Configure the cell...
    Mp3Model *m = self.list[indexPath.row];
    
    cell.textLabel.text = m.name;
    cell.imageView.image = [UIImage imageNamed:m.singerIcon];
    cell.imageView.layer.cornerRadius = 25;
    cell.imageView.layer.masksToBounds = YES;
    
    
    return cell;
}

/* 记录将要点击列表的 indexPath */
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.curSel = indexPath;
    return indexPath;
}

/* 跳转时传值 */
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    PlayerViewController *player = segue.destinationViewController;

    player.curSel = (int)self.curSel.row;
    player.list = self.list;
    
}
@end
